
package ai;

import java.awt.image.BufferedImage;
import java.io.IOException;

public class ScreenImgBinary
{
	public static final int	max	= -1;			//new Color(255, 255, 255).getRGB();
	public static final int	min	= -16777216;	//new Color(0, 0, 0).getRGB();
	
	public static BufferedImage getWaterImg(BufferedImage screenImg)
	{
		int h = screenImg.getHeight();//获取图像的高  
		int w = screenImg.getWidth();//获取图像的宽  
		BufferedImage nbi = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);
		for(int x = 0; x < w; x++)
		{
			for(int y = 0; y < h; y++)
			{
				String str = Integer.toHexString(screenImg.getRGB(x, y));
				int r = Integer.parseInt(str.substring(2, 4), 16);
				int g = Integer.parseInt(str.substring(4, 6), 16);
				int b = Integer.parseInt(str.substring(6, 8), 16);
				if((r > 44) && (r < 130) && (g > 170) && (g < 255) && (b > 17) && (b < 130))
				{
					nbi.setRGB(x, y, ScreenImgBinary.max);
				}else
				{
					nbi.setRGB(x, y, ScreenImgBinary.min);
				}
			}
		}
		return nbi;
	}
	
	public static BufferedImage getBorderImg(BufferedImage screenImg)
	{
		int h = screenImg.getHeight();//获取图像的高  
		int w = screenImg.getWidth();//获取图像的宽  
		BufferedImage mbi = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);
		for(int x = 0; x < w; x++)
		{
			for(int y = 0; y < h; y++)
			{
				String str = Integer.toHexString(screenImg.getRGB(x, y));
				int r = Integer.parseInt(str.substring(2, 4), 16);
				int g = Integer.parseInt(str.substring(4, 6), 16);
				int b = Integer.parseInt(str.substring(6, 8), 16);
				if((r > 170) && (r < 200) && (g > 210) && (g < 240) && (b > 220) && (b < 240))
				{
					mbi.setRGB(x, y, ScreenImgBinary.max);
				}else
				{
					mbi.setRGB(x, y, ScreenImgBinary.min);
				}
			}
		}
		return mbi;
	}
	
	public static void main(String [] args) throws IOException
	{
		System.out.println(ScreenImgBinary.max);
		System.out.println(ScreenImgBinary.min);
	}
}
